Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
beaver-logger
Advanced tools
Front-end logger, which will:
This is a great tool to use if you want to do logging on the client side in the same way you do on the server, without worrying about sending off a million beacons. You can quickly get an idea of what's going on on your client, including error cases, page transitions, or anything else you care to log!
$logger.info(<event>, <payload>);
Queues a log. Options are debug
, info
, warn
, error
.
For example:
$logger.error('something_went_wrong', { error: err.toString() })
$logger.track(<payload>);
Call this to attach general tracking information to the current page. This is useful if the data is not associated with a specific event, and will be sent to the server the next time the logs are flushed.
$logger.startTransition();
Call this when you start an ajax call or some other loading period, with the intention of moving to another page.
$logger.endTransition(<nextStateName>);
Call this when you transition to the next page. beaver-logger will automatically log the transition, and how long it took. The logs will be auto-flushed after this call.
$logger.transition(<nextStateName>);
This is a short-hand for logger.startTransition(); $logger.endTransition(<nextStateName>);
when there is no loading time, and the transition from one state to another is instant. The logs will be auto-flushed after this call.
$logger.init(<config>);
Set the logger up with your configuration options. This is optional. Configuration options are listed below.
$logger.addMetaBuilder(<function>);
Attach a method which is called and will attach general information to the logging payload whenever the logs are flushed
$logger.addMetaBuilder(function() {
return {
current_page: getMyCurrentPage()
};
});
$logger.addPayloadBuilder(<function>);
Attach a method which is called and will attach values to each individual log's payload whenever the logs are flushed
$logger.addPayloadBuilder(function() {
return {
performance_ts: window.performance.now()
};
});
$logger.addTrackingBuilder(<function>);
Attach a method which is called and will attach values to each individual log's tracking whenever the logs are flushed
$logger.addTrackingBuilder(function() {
return {
pageLoadTime: getPageLoadTime()
};
});
$logger.addHeaderBuilder(<function>);
Attach a method which is called and will attach values to each individual log requests' headers whenever the logs are flushed
$logger.addHeaderBuilder(function() {
return {
'x-csrf-token': getCSRFToken()
};
});
$logger.flush();
Flushes the logs to the server side. Recommended you don't call this manually, as it will happen automatically on page transitions, or after a configured interval.
npm install --save beaver-logger
or bower install --save beaver-logger
<script src="/js/beaver-logger.min.js"></script>
or
let $logger = require('beaver-logger');
$logger.init({
// URI to post logs to
uri: '/api/log',
// State name to post logs under
initial_state_name: 'init',
// Interval at which to automatically flush logs to the server
flushInterval: 10 * 60 * 1000,
// Interval at which to debounce $logger.flush calls
debounceInterval: 10,
// Limit on number of logs before auto-flush happens
sizeLimit: 300,
// Supress `console.log`s when `true`
// Recommended for production usage
silent: false,
// Enable or disable heartbeats, which run on an interval
heartbeat: true,
// Heartbeat log interval
heartbeatInterval: 5000,
// Maximum number of sequential heartbeat logs
heartbeatMaxThreshold: 50,
// Monitors for event loop delays and triggers a toobusy event
heartbeatTooBusy: false,
// Event loop delay which triggers a toobusy event
heartbeatTooBusyThreshold: 10000,
// Log levels which trigger an auto-flush to the server
autoLog: ['warn', 'error'],
// Log window.onunload and window.beforeUnload events?
logUnload: true,
// Log unload synchronously, to guarantee the log gets through?
logUnloadSync: false,
// Log performance stats from the browser automatically?
logPerformance: true
});
beaver-logger includes a small node endpoint which will automatically accept the logs sent from the client side. You can mount this really easily:
let beaverLogger = require('beaver-logger/server');
myapp.use(beaverLogger.expressEndpoint({
// URI to recieve logs at
uri: '/api/log',
// Custom logger (optional, by default logs to console)
logger: myLogger,
// Enable cross-origin requests to your logging endpoint
enableCors: false
}))
Or if you're using kraken, you can add this in your config.json
as a middleware:
"beaver-logger": {
"priority": 106,
"module": {
"name": "beaver-logger/server",
"method": "expressEndpoint",
"arguments": [
{
"uri": "/api/log",
"logger": "require:my-custom-logger-module"
}
]
}
}
Setting up a custom logger is really easy, if you need to transmit these logs to some backend logging service rather than just logging them to your server console:
module.exports = {
log: function(req, level, event, payload) {
logSocket.send(JSON.stringify({
level: level,
event: event,
payload: payload
}));
}
}
FAQs
Client side logger.
We found that beaver-logger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.